package com.stu.book.java8sz2.char10;

import lombok.AllArgsConstructor;

import java.util.Optional;

/**
 * @author zhuzi
 * 2022/8/20 17:18
 */
public class FlapMapDemo {
    public static void main(String[] args) {
        Insurance insurance = new Insurance("太平洋保险");
        Person person = new Person(Optional.of(new Car(Optional.of(insurance))));

        Person person1 = Optional.ofNullable(person).orElse(new Person(null));
        System.out.println(person1.car);

    }

    @AllArgsConstructor
    public static class Person {
        private Optional<Car> car;

        public Optional<Car> getCar() {
            return car;
        }
    }

    @AllArgsConstructor
    public static class Car {
        private Optional<Insurance> insurance;

        public Optional<Insurance> getInsurance() {
            return insurance;
        }
    }

    @AllArgsConstructor
    public static class Insurance {
        private String name;

        public String getName() {
            return name;
        }
    }
}
